<template>
  <div>

    <div>CardProvide,router.meta.isbar==={{isbar[1]}}</div>
    <button type="button" @click="getRoutesbar">ccefef</button>
    <hr>
    <ul v-for="items in isbar[1].children  "  >
          {{items}}
      <hr>
      <ul v-if="!items.children">{{items.path}}</ul>
      <ul v-else  v-for="item in items.children">
        <p>这里是标题 {{items.path}}</p>
        <li>{{items.path + '/'+item.path }}</li>
      </ul>


     <!-- <li v-for="item in items.children"><span>{{item}}</span></li>-->
    </ul>
    <ul>
      <button @click="getidcard()">获取身份证</button>
      <li>name:{{randomidcard.name}}</li>
      <li>idcard:{{randomidcard.cardid}}</li>
      <li><button @click="downloadfile">下载（需要chorme）</button></li>
    </ul>

  </div>
</template>

<script>
  import {getRandomName,getRandomIdcard} from '../../util/randomInfo'
  import vue from 'vue'
  export default {
    name: "CardProvide",
    data() {
        return {
        isbar: [],
          randomidcard:{
            name:'',
            cardid:''
          }
       // items:[]
      }
    },
    created () {
      this.isbar = this.$router.options.routes;


    },

    methods: {
      getRoutesbar() {

       this.isbar = JSON.stringify(this.$router.options.routes);
      },
      hasChildren(route){//判断有没有子路由
        return route.children
      },
      getidcard(){
        //console.log("======================getidcard=",getRandomName())
        vue.set(this.randomidcard,'name',getRandomName())
        vue.set(this.randomidcard,'cardid',getRandomIdcard())

      },
      downloadfile(){
        console.log("downloadfile")
        let content = "================================"
        let fileName='idcard.txt'
       /* let blob = new Blob([content])
        let aTag = document.createElement('a')
        aTag.download=filename
        aTag.href=window.URL.createObjectURL(blob)
        aTag.click()
        URL.revokeObjectURL(aTag.href)*/

      /*  var aLink = document.createElement('a');
        var blob = new Blob([content]);
        var evt = document.createEvent("HTMLEvents");
        evt.initEvent("click", false, false);//initEvent 不加后两个参数在FF下会报错, 感谢 Barret Lee 的反馈
        aLink.download = fileName;
        aLink.href = URL.createObjectURL(blob);
        aLink.dispatchEvent(evt);*/

      //https://www.cnblogs.com/webbest/p/8080873.html

        let aTag = document.createElement('a');
        let blob = new Blob([content]);　　// 这个content是下载的文件内容，自己修改
        aTag.download = fileName;　　　　　　// 下载的文件名
        aTag.href = URL.createObjectURL(blob);
        aTag.click();
        URL.revokeObjectURL(blob);
      }
    },
    mounted(){
      this.getidcard()
    },



  }
</script>

<style scoped>

</style>
